package org.example.new_hbps_backend_reconstruction.controller.patient;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.example.new_hbps_backend_reconstruction.common.results.R;
import org.example.new_hbps_backend_reconstruction.service.SleepLogsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

/**
 * @author 丁利军
 * @date 2025年10月27日 11:32
 * @description 睡眠控制器
 */

@RestController
@RequestMapping("/patient/sleep")
@Tag(name = "睡眠日志", description = "根据日期统计患者当日睡眠时长")
@RequiredArgsConstructor
public class SleepLogsController {

    private final SleepLogsService sleepLogsService;

    @Operation(summary = "获取患者某日睡眠时长",
            description = "根据 patientUid 和 date(yyyy-MM-dd) 查询当日睡眠总时长")
    @GetMapping("/dailySummary")
    public R<?> getDailySleepSummary(@RequestParam("patientUid") Long patientUid,
                                     @RequestParam("date") String dateStr) {
        LocalDate date = LocalDate.parse(dateStr);
        return sleepLogsService.getDailySleepSummary(patientUid, date);
    }
}
